#region using directives
using System.Windows.Forms;
using System.Collections.Generic;
using System.Drawing;
using System;
using C4F.DevKit.Speech;
#endregion

namespace SpeechApplication
{
    public partial class SpeechGUI : Form
    {

        #region Constructors

        public SpeechGUI()
        {
            InitializeComponent();
        }
       
        #endregion

        #region Event Handlers
   
        private void btnClose_Click(object sender, System.EventArgs e)
        {
            this.Close();
        }

        private void tabcontrol_SelectedIndexChanged(object sender, System.EventArgs e)
        {
            bool instantiationSuccessful = false;
            try
            {
                switch (tabcontrol.SelectedIndex)
                {
                    case 0:
                        sapiManager1.StopSpeechRecognitionEngine();
                        sapiManager1.StopDictationEngine();
                        break;
                    case 1:
                        try
                        {
                            instantiationSuccessful = sapiManager1.InitializeDictationEngine(null);
                        }
                        catch
                        {
                            throw new Exception("Dictation grammer may not be supported on your machine.");
                        }

                        if (instantiationSuccessful)
                        {
                            sapiManager1.StopSpeechRecognitionEngine();
                            sapiManager1.StartDictationEngine();
                        }
                        break;
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "SpeechGUI", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }

        private void lnkSettings_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
        {
            SpeechSettings form = new SpeechSettings(this.sapiManager1);
            form.ShowDialog();
        }

        #endregion 
       
    }
}